/**
 * Created by geqq on 2018/5/14 0937.
 */
var RefundmentIndex = new Vue({
    el: '#refundment',
    data: {
        datas: {
            'paginator':{},
            'refundList': []
        },
        orderList: [],
        initStatus: true,
        acctFundInfo: {},
        isShowBindAccount: false,
        isShowVerification: false,
        search: {
            pageNo: 1,
            pageSize: 20
        },
        search2: {
            pageNo: 1,
            pageSize: 20,
            payNo: ''
        }
    },
    methods: {
        getRefundList: function () {
            var _this = this;
            _this.setAjaxOptions('/getRefundList', _this.search, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    _this.datas = result.data;
                    Vue.useLayerPage('laypage', _this.datas.paginator, _this.search);
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        getFundFlow: function () {
            var _this = this;
            _this.setAjaxOptions('/getFundFlow', _this.search2, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    _this.orderList = result.data.billList;
                    _this.initStatus = false;
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        refundOffLine: function(record){
            var _this = this;
            _this.setAjaxOptions('/confirmRefundOffLine', {"refundId": 1}
                , function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    record.status = 1;
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        refundOnLine: function(record){
            var _this = this;
            _this.setAjaxOptions('/confirmRefundOnLine', {payNo : record.payNo, amount: record.amount}
                , function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    record.status = 1;
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        showBindAccount: function () {
            if (!this.isShowBindAccount) {
                this.isShowBindAccount = !this.isShowBindAccount;
            }

            Vue.useLayerForm();
        },
        showVerification: function () {
            if (!this.isShowVerification) {
                this.isShowVerification = !this.isShowVerification;
            }

            Vue.useLayerForm();
        }
    },
    mixins: [AjaxMixin, StatusMixin, UserMixin],
    mounted: function () {
        Vue.useLayerElement();
        this.getRefundList();
    },
    watch: {
        'search': {
            handler: function (val, oldVal) {
                this.getRefundList();
            },
            deep: true
        },
        'search2': {
            handler: function (val, oldVal) {
                if(val.payNo == '' || val.payNo == null){
                    this.orderList = [];
                    this.initStatus = false;
                }else{
                    this.getFundFlow();
                }
            },
            deep: true
        }
    }
});